import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Req,
  Query,
} from '@nestjs/common';
import { DailyService } from './daily.service';
import { UpdateDailyDto } from './dto/update-daily.dto';
import { RequireLogin, UserInfo } from 'src/custom.decorator';
import { Request } from 'express';

@Controller('daily')
export class DailyController {
  constructor(private readonly dailyService: DailyService) {}

  @RequireLogin()
  @Post()
  async create(
    @Body() createDailyDto: {content: string, avatar: string, images?:string},
    @UserInfo('userId') userId: number,
    @UserInfo('username') authorName: string,
    @Req() req: Request,
  ) {
    return await this.dailyService.create({...createDailyDto, ip: req.ip, userId, authorName});
  }

  @Get()
  findAll(@Query('userId') userId: number) {
    return this.dailyService.findAll(userId);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.dailyService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateDailyDto: UpdateDailyDto) {
    return this.dailyService.update(+id, updateDailyDto);
  }

  @RequireLogin()
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.dailyService.remove(+id);
  }
}
